import { defHttp } from '@/utils/http/axios';
import { BasicFetchResult } from './model/baseModel';
import { MenuModel } from './model/menuModel';
import { ErrorMessageMode } from '#/axios';

export const getMenuList = () => {
  return defHttp.get<MenuModel>(
    {
      url: '/system/menus',
    }
  );
};

export const getMenuManageList = () => {
  return defHttp.get<BasicFetchResult<MenuModel>>(
    {
      url: '/system/menus/manage-list',
    }
  );
};

export function createMenu(params: MenuModel, mode: ErrorMessageMode = 'message') {
  return defHttp.post<MenuModel>(
    {
      url: '/system/menus',
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function editMenu(id: number, params: MenuModel, mode: ErrorMessageMode = 'message') {
  return defHttp.put<MenuModel>(
    {
      url: `/system/menus/${id}`,
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function deleteMenu(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.delete(
    {
      url: `/system/menus/${id}`,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}